<%@page import="sdr.abstractFactory"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="sdr.elementos.usuario"%>
<%@page import="org.hibernate.Session"%>
<%@page import="sdr.HibernateUtil"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<%

%>

    
    <body>
        <form name="form" method="POST">
         <%
 Session hsession ;
  hsession = HibernateUtil.getSessionFactory().getCurrentSession();
       hsession.beginTransaction();

 List result = hsession.createCriteria(usuario.class).list();
        if (result.size() > 0) {
            out.println("<h2>Usuarios en db:</h2>");
            out.println("<table border='1'>");
            out.println("<tr>");
            out.println("<th>Nombre</th>");
            out.println("<th>Correo</th>");
            out.println("<th>Opciones</th>");
            out.println("</tr>");
            Iterator it = result.iterator();
            while (it.hasNext()) {
                usuario event = (usuario) it.next();
                if("Borrar".equals(    request.getParameter("del"+event.getId()))){
event.delete();
}else{
                    
                if("Guardar".equals(    request.getParameter("save"))){
                event.setCorreo((String)request.getParameter("cor"+event.getId()));
                event.setNombres((String)request.getParameter("nom"+event.getId()));
                event.update();
                }
                
                out.println("<tr>");
                out.println("<td>");

                         %>  <input  type = "text" name = "nom<%=event.getId()%>" value =
                                        "<%=event.getNombres()%>" />            
                                         <%              
                                     out.println(                  "</td>");
                out.println("<td>");

                         %>  <input  type = "text" name = "cor<%=event.getId()%>" value =
                                        "<%=event.getCorreo()%>" />            
                                         <%              
                                     out.println(                  "</td>");


                                                                                   
        out.println("<td>");
         %><input type="submit" value="Borrar" name="del<%=event.getId()%>" /><%
        out.println("</td>");
        
           
                                         //out.println("<td>" + dateFormatter.format(event.getDate()) + "</td>");
                out.println("</tr>");

}
            }
            
            
            
             out.println("<tr>");
                out.println("<td></td>");
                   out.println("<td></td>");
           
        out.println("<td>");
         %><input type="submit" value="Guardar" name="save" /><%
        out.println("</td>");
           
                                         //out.println("<td>" + dateFormatter.format(event.getDate()) + "</td>");
                out.println("</tr>");
            out.println("</table>");
        }
// hsession.close();
%>
        
</form>
        
       
        </p>
    </body>
</html>
